import { reactive } from "vue";
import type { FormRules } from "element-plus";



export const DOMAIN_PATTERN = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
/** 自定义表单规则校验 */
export const formRules = reactive(<FormRules>{
  cloudName: [
    { required: true, message: "服务云名称为必填项", trigger: "blur" }
  ],
  cloudBasePath: [
    {
      required: true,
      validator: (rule, value, callback) => {
        if (value === "") {
          callback(new Error("服务云地址为必填项"));
        } else if (!DOMAIN_PATTERN.test(value)) {
          callback(new Error("服务云地址必须为域名地址"));
        } else {
          callback();
        }
      },
      trigger: "blur"
    }
  ]
});
